define([ "Zepto", "underscore", "Backbone", "Handlebars",
﻿  ﻿  "text!templates/faculty/facultylist.html",
﻿  ﻿  "views/faculty/facultylistitemview" ], function($, _, Backbone, Handlebars,
﻿  ﻿  template, FacultyListItemView) {

﻿  var FacultyListView = Backbone.View.extend({

﻿  ﻿  template : Handlebars.compile(template),

﻿  ﻿  initialize : function() {
﻿  ﻿  ﻿  this.model.bind("reset", this.render, this);
﻿  ﻿  },

﻿  ﻿  render : function(eventName) {
﻿  ﻿  ﻿  $(this.el).empty();
﻿  ﻿  ﻿  
      _.each(this.model.models, function(faculty) {
﻿  ﻿  ﻿  ﻿  $(this.el).append(new FacultyListItemView({
		  	tagName : 'a', //Crea un nuovo tag <a> invece di usarne uno già presente nel DOM
			attributes : {
				'href' : '#guide/'+faculty.get('objectId')
			},
﻿  ﻿  ﻿  ﻿  ﻿  	model : faculty
﻿  ﻿  ﻿  ﻿  }).render().el);
﻿  ﻿  ﻿  }, this);
﻿  ﻿  ﻿  // $('#myList').listview('refresh');
﻿  ﻿  ﻿  return this;
﻿  ﻿  },

﻿  ﻿  postRender : function(eventName) {
﻿  ﻿  ﻿  var scrollableframe = new iScroll('scrollableframe', {
﻿  ﻿  ﻿  ﻿  useTransition : false,
﻿  ﻿  ﻿  ﻿  checkDOMChanges : true,
﻿  ﻿  ﻿  ﻿  hideScrollbar : true,
﻿  ﻿  ﻿  ﻿  fixedScrollbar : true,
﻿  ﻿  ﻿  ﻿  bounceLock : true });
﻿  ﻿  },

﻿  ﻿  events : {
﻿  ﻿  ﻿  'touchstart .list-item' : 'over',
﻿  ﻿  ﻿  'touchend .list-item' : 'left',
﻿  ﻿  ﻿  'touchcancel .list-item' : 'left',
﻿  ﻿  },

﻿  ﻿  over : function(event) {
﻿  ﻿  ﻿  $(event.currentTarget).addClass('fake-active');
﻿  ﻿  },

﻿  ﻿  left : function(event) {
﻿  ﻿  ﻿  $(event.currentTarget).removeClass('fake-active');
﻿  ﻿  }
﻿  });

﻿  return FacultyListView;

});